def xtree(data):
    if not data:
        return data
    lst=[]
    tree={}
    for i in data:
        i["label"] = i["name"]
        tree[i["id"]]=i
    for j in data:
        pid = j["pid"]
        if pid == 0:
            lst.append(j)
        else:
            if "children" not in tree[pid]:
                tree[pid]["children"] = []
            tree[pid]["children"].append(j)
    return lst